<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\View;

class VerifyAdminSession
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if ( Session::has('ADMIN_INFO') )
        {
            $info = Session::get('ADMIN_INFO');
            View::share('admin', $info);
            return $next($request);
        }
        else
        {
            return redirect('/admin/index');
        }
    }
}
